#include <time.h>
#include <math.h>
#include <stdlib.h>
#define SIZE 100
#include <iostream>
using namespace std;
//const int SIZE = 100;



typedef struct  {
	LinkElemType pData;
	int size;
}List, *LinkList;

bool InitScore(Score& score){
	score.pScore = new double[SIZE];
	if (score.pScore == NULL)
		return false;
	score.size = 0;
	return true;
}

bool GenScore(Score& score, int n){
	if (n <= 0 || n > SIZE)
		return false;

	srand(time(NULL));
	for (int i = 0; i < n; i ++)
		score.pScore[i] = (rand() % 401 + 600) / 10.;
	score.size = n;

	return true;
}

void ShowScore(Score score){
	for (int i = 0; i < score.size; i ++){
		cout << score.pScore[i] << "  ";
		if ((i + 1) % 10 == 0)
			cout << endl;
	}
	cout << endl;
}

bool GetScore(Score score, int i, double& elem) {
	if (i < 1 || i > score.size)
		return false;

	elem = score.pScore[i - 1];
	return true;
}

int LocateScore(Score score, double elem){
	int loc = 0;
	for (int i = 0; i < score.size; i ++)
		if (fabs(elem - score.pScore[i]) < 1.E-7){
			loc = i + 1;
			break;
		}

	return loc;
}

bool InsertScore(Score& score, double elem, int index){//3
	if (index < 1 || index > score.size)
		return false;
	if (score.size >= SIZE)
		return false;

	for (int i = score.size; i >= index; i --)
		score.pScore[i] = score.pScore[i - 1];

	score.pScore[index - 1] = elem;
	score.size ++;
	return true;
}

bool DeleteScore(Score& score, int index) {
	if (index < 1 || index > score.size)
		return false;

	for (int i = index - 1; i < score.size - 1; i ++)
		score.pScore[i] = score.pScore[i + 1];

	score.size --;
	return true;
}

void ReverseScore(Score& score) {
	if (score.size == 0)
		return;

	for (int i = 0; i < score.size / 2; i ++) {
		double t = score.pScore[i];
		score.pScore[i] = score.pScore[score.size - i - 1];
		score.pScore[score.size - i - 1] = t;
	}
}
